package com.wonders.hisdoctor.station.project.hisqueue.controller;

import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.utils.validator.ValidateUtils;
import com.wonders.his.framework.dto.LoginUserDTO;
import com.wonders.his.framework.service.TokenService;
import com.wonders.hisdoctor.station.project.hisqueue.service.IQueueService;
import com.wonders.hisdoctor.station.project.hisqueue.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Description: 就诊队列
 *
 * @author zhanghaonan
 * <p>
 * Create: 2021-01-18 16:37
 */
@Api(tags = "就诊队列")
@RestController
@RequestMapping("/queue")
public class QueueController {

    @Autowired
    private IQueueService queueService;

    @Autowired
    private TokenService tokenService;

    @ApiOperation("查询病人信息")
    @PostMapping("/selectPatientInfo")
    public BaseResult<PatientInfoResponseVo> selectPatientInfo(@RequestBody PatientInfoRequestVo requestVo) {
        return BaseResult.success(queueService.selectPatientInfo(requestVo));
    }

    @ApiOperation("更新就诊状态为在诊")
    @PostMapping("/updateRegStatus")
    public BaseResult<Integer> updateRegStatus(@RequestBody PatientInfoRequestVo requestVo) {
        ValidateUtils.validateEntity(requestVo);
        return BaseResult.success(queueService.updateRegStatus(requestVo));
    }

    @ApiOperation("查询就诊队列")
    @PostMapping("/selectWaitQueue")
    public BaseResult<WaitQueueResponseVo> selectWaitQueue(@RequestBody WaitQueueRequestVo requestVo) {
        return BaseResult.success(queueService.selectWaitQueue(requestVo));
    }

    @ApiOperation("用户科室下拉框")
    @GetMapping("/selectDeptByEmpNo")
    public BaseResult<List<DeptVo>> selectDeptByEmpNo(@RequestParam("empNo") String empNo, @RequestParam("hospitalCode") String hospitalCode) {
        return BaseResult.success(queueService.selectDeptByEmpNo(empNo, hospitalCode));
    }

    @ApiOperation("号别下拉框")
    @PostMapping("/selectClinicIndex")
    public BaseResult<List<ClinicIndexVo>> selectClinicIndex(@RequestBody ClinicIndexVo vo) {
        return BaseResult.success(queueService.selectClinicIndex(vo));
    }

    @ApiOperation("查询病人就诊记录")
    @GetMapping("/selectClinicMaster/{patientId}")
    public BaseResult<List<ClinicMasterQueryVo>> selectClinicMaster(@PathVariable String patientId, HttpServletRequest request) {
        LoginUserDTO loginUserDTO = tokenService.getLoginUserDTO(tokenService.getToken(request));
        String hospitalCode = "";
        if (loginUserDTO != null && loginUserDTO.getSysSysuserVo() != null) {
            hospitalCode = loginUserDTO.getSysSysuserVo().getHospitalCode();
        }
        return BaseResult.success(queueService.selectClinicMaster(patientId, hospitalCode));
    }

    @ApiOperation("完成就诊")
    @PostMapping("/finishVisit")
    public BaseResult<Integer> finishVisit(@RequestBody PatientInfoRequestVo requestVo) {
        ValidateUtils.validateEntity(requestVo);
        return BaseResult.success(queueService.finishVisit(requestVo));
    }

    @ApiOperation("判断是否可以取消就诊")
    @PostMapping("/checkCancelVisit")
    public BaseResult<Boolean> checkCancelVisit(@RequestBody PatientInfoRequestVo requestVo) {
        ValidateUtils.validateEntity(requestVo);
        return BaseResult.success(queueService.checkCancelVisit(requestVo));
    }

    @ApiOperation("取消就诊")
    @PostMapping("/cancelVisit")
    public BaseResult<Integer> cancelVisit(@RequestBody PatientInfoRequestVo requestVo) {
        ValidateUtils.validateEntity(requestVo);
        return BaseResult.success(queueService.cancelVisit(requestVo));
    }

    @ApiOperation("号类下拉框")
    @PostMapping("/selectClinicType")
    public BaseResult<List<ClinicIndexVo>> selectClinicType(@RequestBody ClinicIndexVo vo) {
        return BaseResult.success(queueService.selectClinicType(vo));
    }

    @ApiOperation("查询就诊队列(根据号类)")
    @PostMapping("/selectQueueByClinicType")
    public BaseResult<WaitQueueResponseVo> selectQueueByClinicType(@RequestBody WaitQueueRequestVo requestVo, HttpServletRequest request) {
        return BaseResult.success(queueService.selectQueueByClinicType(requestVo, request));
    }

}
